package com.example.xitong;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.TextView;

import com.gyf.immersionbar.ImmersionBar;

import java.util.Timer;
import java.util.TimerTask;

public class Welcome extends AppCompatActivity {

    int i=5;
    int flag=0;
    Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);

            if (msg.what==0){
                i--;
                te.setText("倒计时"+i+"秒"+" 点击跳过");


                if (i==0&&flag==0){
                    finish();
                    Intent intent=new Intent(Welcome.this,Login.class);
                    startActivity(intent);
                }
            }
        }
    };
    private TextView te;
    private Timer timer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);


        ImmersionBar.with(this)
                // .statusBarColor(R.color.touming)
                .init();

        te = findViewById(R.id.twe);

        te.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
                Intent intent=new Intent(Welcome.this,Login.class);
                startActivity(intent);
                flag=1;
            }
        });

        timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {

                handler.sendEmptyMessage(0);

            }
        },0,1000);
    }
}